function [ cMat img] = drawConfusionMatrix(dists,testLbls,trainLbls)
%testLbls is 1xN and trainLbls is 1xM
%dists is a NxM matrix of L2 distances
%where dists(i,j) is the distance between test digit i and training digit j
%Assumes a 1-nearest neighbor classifier

cMat=zeros(10,10);

N=size(dists,1);
M=size(dists,2);

assert(size(testLbls,2)==N);
assert(size(trainLbls,2)==M);

for i=1:N
    testLbl = testLbls(i);
    [~,I]=min(dists(i,:));
    matchLbl=trainLbls(I(1));
    cMat(testLbl+1,matchLbl+1) = cMat(testLbl+1,matchLbl+1) + 1;
end


%make image bigger
img=zeros(500,500);
for i=1:size(img,1)
    for j=1:size(img,2)
        img(i,j)=cMat(ceil(10*i/size(img,1)),ceil(10*j/size(img,2)));
    end
end

%normalize image
img=img/N;

%increase brightness
img=20*img;

figure;
imshow(img);

end

